using System;
using System.Collections.Generic;
using System.Linq;

namespace DA.AnimGraph.Editor {
    public class AGEGlobal {
        private static AGEGlobal instance;

        public static AGEGlobal GetInstance() {
            if (instance == null) {
                instance = new AGEGlobal();
            }
            return instance;
        }

        internal readonly AGEStyle style;
        internal readonly AGEClipboard clipboard;
        internal readonly AGAFileTool fileTool;
        internal readonly AGESetting setting;
        internal readonly AGEPreview preview;


        private List<(Type, AGToolAttribute)> tools;
        private List<(Type, AGBatchToolAttribute)> batchTools;

        private AGEGlobal() {
            style = new();
            clipboard = new();
            fileTool = new();
            setting = new AGESetting();
            preview = new AGEPreview();
        }

        internal (List<(Type, AGToolAttribute)> tools, List<(Type, AGBatchToolAttribute)> batchTools) CollectTools() {
            if (tools == null && batchTools == null) {
                tools = TypeRegisterUtility.GetAllClassesByAttributeWhereBaseClass<AGToolAttribute, IAGTool>();
                batchTools = TypeRegisterUtility.GetAllClassesByAttributeWhereBaseClass<AGBatchToolAttribute, IAGBatchTool>();
            }
            return (tools, batchTools);
        }

        internal AnimGraphEditorWindow[] GetEnableWindows() {
            var ageWindows = AnimGraphEditorWindow.GetWindows().Where(w => w.hasContext).ToArray();
            return ageWindows;
        }

    }
}
